﻿package com.zkingsoft.actions.admin.pc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import com.zkingsoft.services.pc.PcMenuCategoryService;
import com.zkingsoft.services.pc.PcMicroElementService;
import com.zkingsoft.services.pc.impl.PcMicroElementServiceImpl;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcMenuCategory;
import com.zkingsoft.model.pc.PcMenuCategory;
import com.zkingsoft.model.pc.PcMicroElement;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.util.WebUtil;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.pojo.AjaxResult;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zkingsoft.anotations.RemoveRequestToken;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-14 14:37
 */
@Controller
@RequestMapping(value = "admin/pcMenuCategory")
public class PcMenuCategoryController extends BaseController{

	@Resource
	private PcMenuCategoryService pcMenuCategoryService;
	
	@Resource
	private MatrixAdapter matrixAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="PcMenuCategory_BEV";
	
	public static final String fnCode = "PcMenuCategory";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(PcMenuCategory pcMenuCategory, PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted(search);
		return showList(pcMenuCategoryService, pcMenuCategory, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   
	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(PcMenuCategory pcMenuCategory) {
		if (pcMenuCategory.getMeuId() != null) {
	   		matrixAdapter.isBtnPermitted(edit);
	   		pcMenuCategory.setMeuId(((PcMenuCategory)WebUtil.getSessionAttribute(BEV)).getMeuId());
	   		AjaxResult result=modify(pcMenuCategoryService, WebUtil.getSessionAttribute(BEV), pcMenuCategory, "菜谱分类");
			WebUtil.setSessionAttribute(BEV,pcMenuCategory);
			return  result;
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(pcMenuCategoryService, pcMenuCategory, "菜谱分类");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		PcMenuCategory pcMenuCategory;
		if (id != null) {
			pcMenuCategory = pcMenuCategoryService.findById(id);
			WebUtil.getRequest().setAttribute("obj", pcMenuCategory);
			WebUtil.setSessionAttribute(BEV, pcMenuCategory);
			
		}
		
		
	
		return "admin/pc/PcMenuCategory-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		matrixAdapter.isBtnPermitted(del);
		return remove(pcMenuCategoryService, keys);
	}
 	/**
	 * 显示所有功能
	 */
 	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return findByModel(pcMenuCategoryService, null);
	}
 	/**
	 * id查询
	 * @param PcMenuCategory
	 */
	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(PcMenuCategory pcMenuCategory) {
		pcMenuCategory=pcMenuCategoryService.findById(pcMenuCategory.getMeuId());
		WebUtil.setSessionAttribute(BEV, pcMenuCategory);
		return new AjaxResult(AjaxResult.STATUS_OK, Arrays.asList(pcMenuCategory));
	}
	
}